<template>
  <div class="login">
    <!-- 卡片 -->
    <div class="login_box">
      <el-card class="box-card">
        <!-- 图片区 -->
        <div class="avatar_box">
          <img src="../assets/2.jpg" />
        </div>

        <el-form :model="loginForm" label-width="0px" class="login_form">

          <el-form-item>
            <el-input type="input" placeholder="请输入账号" v-model="loginForm.username"></el-input>
          </el-form-item>

          <el-form-item>
            <el-input type="passeorld" placeholder="请输入密码" v-model="loginForm.passworld">
            </el-input>
          </el-form-item>

          <el-form-item class="btns">
            <el-button type="primary" @click="denglu">登录</el-button>
            <el-button type="info" @click="chongzhi">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, getCurrentInstance, computed } from 'vue'
const { proxy } = getCurrentInstance()
import { ElMessage } from 'element-plus'
import { useMainStore } from '../store/index';
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const mainStore = useMainStore()

defineOptions({
  name: 'login'
})
let loginForm = reactive({
  username: "admin",
  passworld: "admin",
})

let loginFormRule = reactive({
  username: [
    { required: true, message: "请输入登录名", trigger: "blur" },
    {
      min: 3,
      max: 10,
      message: "登录名长度在 3 到 10 个字符",
      trigger: "blur",
    },
  ],
  password: [
    { required: true, message: "请输入密码", trigger: "blur" },
    {
      min: 6,
      max: 15,
      message: "密码长度在 6 到 15 个字符",
      trigger: "blur",
    },
  ],
})

let denglu = async () => {
  let res = await proxy.$api.getMenu(loginForm)
  console.log('getMenu', res);
  ElMessage({
    message: "登录成功",
    type: "success",
  });
  mainStore.updateMenu(res.menuList)
  mainStore.setToken(res.token)
  mainStore.setPermission(res.permission)
  // mainStore.addMenu(router)
  router.push("/home");
}
let chongzhi = () => {
  loginForm.username = "";
  loginForm.password = "";
}

</script>

<style scoped lang="less">
.login {
  height: 100%;
  background-image: url("../assets/1.jpg");
  background-size: 100% 100%;
}

.login_box {
  width: 450px;
  height: 300px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  .avatar_box {
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 3px;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;

    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 2%;
  box-sizing: border-box;

  ::v-deep .el-form-item__content {
    justify-content: center;
  }

}


.el-card {
  background-color: rgba(255, 255, 255, 0.1);
}

.el-input {
  width: 90%;
}
</style>